$(document).ready(function () {
    addTimeOutAction()

    $('#changePassword-userName').val(window.localStorage.userID)

})

function changePassword() {
    var userName = $('#changePassword-userName').val()
    var oldPassword = $('#changePassword-oldPassword').val()
    if(oldPassword == ''){
        alert("请输入原始密码！")
        return
    }
    var newPassword = $('#changePassword-newPassword').val()
    if(newPassword == ''){
        alert("请输入新密码！")
        return
    }
    var reNewPassword = $('#changePassword-reNewPassword').val()
    if(reNewPassword == ''){
        alert("请重新确认新密码！")
        return
    }

    var urlStr = ipPort + '/user/updatePassword?id=' + userName + '&oldPassword=' + oldPassword
        + '&newPassword=' + newPassword + '&reNewPassword=' + reNewPassword
    console.log(urlStr)
    $.ajax({
        url:urlStr,
        dataType:'json',
        type:'post',
        success:function (obj) {
            if(obj.code == 0){
                alert(obj.message)
                $.ajax({
                    url: ipPort + '/user/logout',
                    type: 'get',
                    success: function (obj) {
                        if(obj.code == 0){
                            document.location = 'login.html'
                        }else{
                            alert(obj.message)
                        }
                    },
                    error: function (err) {
                        console.log(err)
                    }
                })
            }else{
                alert(obj.message)
            }
        },
        error:function (error) {
            console.log(error)
        }
    })
}
function cancelChangePassword() {
    $('#changePassword-oldPassword').val('')
    $('#changePassword-newPassword').val('')
    $('#changePassword-reNewPassword').val('')
}